package io.renren.entity;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.renren.common.utils.Constant;
import io.renren.param.SeatApplicationSaveParam;
import io.renren.param.SeatSaveParam;
import io.renren.param.SeatUpdateParam;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.io.Serializable;
import java.util.Date;

/**
 * 工位申请记录
 *
 * @author 1
 * @email 1@2.com
 * @date 2021-11-19 11:03:23
 */
@Data
@TableName("seat_application")
public class SeatApplicationEntity implements Serializable {
	private static final long serialVersionUID = 1L;

	/**
	 *
	 */
	@TableId
	private Long id;
	/**
	 * 工位id
	 */
	private Long seatId;
	/**
	 * 预定工位的员工id
	 */
	private String employeeId;
	/**
	 * 预定工位的员工id
	 */
	private String department;
	/**
	 * 开始时间
	 */
	private Date startTime;
	/**
	 * 结束时间
	 */
	private Date endTime;
	/**
	 * 预定状态：applied-已申请，signed in-已签到，started-已开始，over-已结束
	 */
	private String state;
	/**
	 * 创建时间
	 */
	private Date createTime;
	/**
	 * 更新时间
	 */
	private Date updateTime;
	/**
	 * 工号
	 */
	private String employeeCode;
	/**
	 * 姓名
	 */
	private String employeeName;

	private String compId;
	/**
	 * 邮箱
	 */
	private String email;

	/* 用来保存员工每天或每周的 工作目标 */
	private String workTarget;

	public static SeatApplicationEntity convertFor(SeatApplicationSaveParam param) {
		SeatApplicationEntity seatApplicationEntity = new SeatApplicationEntity();
		if (param == null) {
			return seatApplicationEntity;
		}
		BeanUtils.copyProperties(param, seatApplicationEntity);
//		seatApplicationEntity.setEndTime(DateUtil.offsetHour(param.getStartTime(), param.getDuration()));
		seatApplicationEntity.setCreateTime(new Date());
		seatApplicationEntity.setUpdateTime(new Date());
		seatApplicationEntity.setState(Constant.ApplicationState.APPLIED.getValue());
		return seatApplicationEntity;
	}

	public static SeatApplicationEntity convertForFixedSeat(SeatApplicationSaveParam param) {
		SeatApplicationEntity seatApplicationEntity = new SeatApplicationEntity();
		if (param == null) {
			return seatApplicationEntity;
		}
		BeanUtils.copyProperties(param, seatApplicationEntity);
		seatApplicationEntity.setStartTime((new Date()));
		seatApplicationEntity.setEndTime(DateUtil.offsetHour(new Date(), 87600)); // 87600 = 10年
		seatApplicationEntity.setCreateTime(new Date());
		seatApplicationEntity.setUpdateTime(new Date());
		seatApplicationEntity.setState(Constant.ApplicationState.APPLIED.getValue());
		return seatApplicationEntity;
	}

	public static SeatApplicationEntity convertFor(SeatSaveParam param) {
		SeatApplicationEntity seatApplicationEntity = new SeatApplicationEntity();
		if (param == null) {
			return seatApplicationEntity;
		}
		BeanUtils.copyProperties(param, seatApplicationEntity);

		seatApplicationEntity.setSeatId(param.getId());
		seatApplicationEntity.setEmployeeName(param.getName());

		final Date startTime = new Date();
		seatApplicationEntity.setStartTime(startTime);
		seatApplicationEntity.setEndTime(DateUtil.offsetHour(startTime, 87600)); // 87600 = 10年
		seatApplicationEntity.setCreateTime(startTime);
		seatApplicationEntity.setUpdateTime(startTime);
		seatApplicationEntity.setState(Constant.ApplicationState.APPLIED.getValue());

		return seatApplicationEntity;
	}

	public static SeatApplicationEntity convertFor(SeatUpdateParam param) {
		SeatApplicationEntity seatApplicationEntity = new SeatApplicationEntity();
		if (param == null) {
			return seatApplicationEntity;
		}
		BeanUtils.copyProperties(param, seatApplicationEntity);

		seatApplicationEntity.setSeatId(param.getId());
		seatApplicationEntity.setEmployeeName(param.getName());

		final Date startTime = new Date();
		seatApplicationEntity.setStartTime(startTime);
		seatApplicationEntity.setEndTime(DateUtil.offsetHour(startTime, 87600)); // 87600 = 10年
		seatApplicationEntity.setCreateTime(startTime);
		seatApplicationEntity.setUpdateTime(startTime);
		seatApplicationEntity.setState(Constant.ApplicationState.APPLIED.getValue());

		return seatApplicationEntity;
	}


}
